package com.xlj.androidmvpdemo.register;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.xlj.androidmvpdemo.R;
import com.xlj.androidmvpdemo.view.FloatLabel;

/**
 * Created by laiyingtang on 2016/8/22.
 */
public class RegisterActivity extends Activity {
    FloatLabel phone;
    private Handler handler=new Handler();
    FloatLabel password;
    Button btn_register;
    ProgressBar progressBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        phone= (FloatLabel) findViewById(R.id.label_phone);
        password= (FloatLabel) findViewById(R.id.label_password);
        btn_register= (Button) findViewById(R.id.btn_register);
        progressBar= (ProgressBar) findViewById(R.id.progress);

        password.getEditText().setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);//密码设置不可见


        btn_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                initViewData();
            }
        });
    }

    /**
     * 获取数据
     */
    private void initViewData() {
        String phoneText=phone.getEditText().getText().toString().trim();
        String pwdText=password.getEditText().getText().toString().trim();
        if(phoneText.isEmpty()){
            Toast.makeText(this,"请输入手机号",Toast.LENGTH_SHORT).show();
        }else if(pwdText.isEmpty()){
            Toast.makeText(this,"请输入密码",Toast.LENGTH_SHORT).show();
        }else{
            progressBar.setVisibility(View.VISIBLE);
            load();//隐藏progressbar
        }
    }
    private void load(){
       handler.postDelayed(new Runnable() {
           @Override
           public void run() {
               progressBar.setVisibility(View.INVISIBLE);
               Toast.makeText(RegisterActivity.this,"测试成功",Toast.LENGTH_SHORT).show();
           }
       },2000);
    }
}
